﻿using System;
using System.IO;

namespace SourcesUnPacker
{
    public class RoleAnimationData
    {
        public int[] Frames { get; set; }
        public int[] Changes { get; set; }

        public static RoleAnimationData read(BinaryReader reader)
        {   
            var animationData = new RoleAnimationData();

            int framesLength = reader.ReadInt32();
            animationData.Frames = new int[framesLength];
            if (framesLength>0)
            {
                // Console.WriteLine("framesLength "+framesLength);
            }
          
            // 读取Frames数组的内容
            for (int i = 0; i < framesLength; i++)
            {
                animationData.Frames[i] = reader.ReadInt32();
            }
            //打印下frames
            if (framesLength>0)
            {
                // Console.WriteLine("Frames: " + string.Join(",", animationData.Frames));
            }
            // 读取Changes数组，这里假设其长度与Frames数组相同
            animationData.Changes = new int[framesLength];
            if (animationData.Changes.Length>2)
            {
                
                animationData.Changes[1] = 0;
                for (int i = 1; i < framesLength; i++)
                {
                    if (animationData.Frames[i - 1] == animationData.Frames[i])
                    {
                        animationData.Changes[i] = animationData.Changes[i - 1];
                    }
                    else
                    {
                        animationData.Changes[i] = animationData.Changes[i - 1] + 1;
                    }
                }
            }
          
            return animationData;
        }
    }
}